//
//  NSString+SYExtension.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/20.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "NSString+SYExtension.h"

static NSNumberFormatter * PZDecimalNumberFormatter(NSUInteger scale,NSNumberFormatterStyle formatterStyle){
    
    static NSNumberFormatter *numberFormatter;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        numberFormatter = [NSNumberFormatter new];
        numberFormatter.alwaysShowsDecimalSeparator = YES;
        numberFormatter.minimumIntegerDigits = 1;
    });
    
    numberFormatter.numberStyle = formatterStyle;
    numberFormatter.minimumFractionDigits = scale;
    return numberFormatter;
}
// CalculationType计算类型
typedef NS_ENUM(NSInteger,CalculationType){
    CalculationAdding,//加
    CalculationSubtracting,//减
    CalculationMultiplying,//乘
    CalculationDividing,//除 /分
};

@implementation NSString (SYExtension)


//获取多少字节
- (int)getByteNum
{
    int strlength = 0;
    char* p = (char*)[self cStringUsingEncoding:NSUnicodeStringEncoding];
    for (int i=0 ; i<[self lengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++) {
        if (*p) {
            p++;
            strlength++;
        }
        else {
            p++;
        }
    }
    return strlength;
}
//截取制定字节数
- (NSString *)subStringByByteWithIndex:(NSInteger)index
{
    
    NSInteger sum = 0;
    
    NSString *subStr = [[NSString alloc] init];
    
    for(int i = 0; i<[self length]; i++){
        
        unichar strChar = [self characterAtIndex:i];
        
        if(strChar < 256){
            sum += 1;
        }
        else {
            sum += 2;
        }
        if (sum >= index) {
            
            subStr = [self substringToIndex:i+1];
            return subStr;
        }
        
    }
    return subStr;
}


+(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width
{
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentJustified;
    paraStyle.lineSpacing = 2;
    paraStyle.hyphenationFactor = 0.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@0.0f
                          };
    
    CGSize size = [str boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return size.height;
    
    
}

+(NSAttributedString *)createAttriStringWithString:(NSString *)string andSpace:(CGFloat)space Font:(UIFont *)font
{
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentJustified;
    paraStyle.lineSpacing = space; //设置行间距
    paraStyle.hyphenationFactor = 0.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    //设置字间距 NSKernAttributeName:@1.5f
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@0.0f
                          };
    
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:string attributes:dic];
    
    return attributeStr;
}

+(NSAttributedString *)createLineWrapAttriStringWithString:(NSString *)string andLineSpace:(CGFloat)space withWrapSpace:(CGFloat)wrapSpace Font:(UIFont *)font
{
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentJustified;
    paraStyle.lineSpacing = space; //设置行间距
    paraStyle.hyphenationFactor = 0.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    //设置字间距 NSKernAttributeName:@1.5f
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@(wrapSpace)
                          };
    
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:string attributes:dic];
    
    return attributeStr;
}

+(CGFloat)getWrapSpaceLabelHeight:(NSString *)str withFont:(UIFont *)font withWidth:(CGFloat)width andWrapSpace:(CGFloat)wrapSpace withSpace:(CGFloat)space
{
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentJustified;
    paraStyle.lineSpacing = space;
    paraStyle.hyphenationFactor = 0.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@(wrapSpace)
                          };
    
    CGSize size = [str boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return size.height;
}



+(NSString *)dictionaryToJson:(NSDictionary *)dict
{
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&parseError];
    
    if (parseError) {
        DDLog(@"字典转字符串失败")
        
        return nil;
    }
    
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
}

+(NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
    
    if (jsonString == nil) {
        
        return nil;
        
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    
    NSError *err;
    
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                         
                                                        options:NSJSONReadingMutableContainers
                         
                                                          error:&err];
    
    if(err) {
        
        DDLog(@"json解析失败：%@",err)
        
        return nil;
        
    }
    
    return dic;
    
}


+(CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *attrs = @{NSFontAttributeName : font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}


#pragma mark - 时间转化
+ (NSString *)timeIntervalToMMSSFormat:(NSTimeInterval)interval
{
    if ((NSInteger)interval < 0) {
        return @"00:00";
    }
    NSInteger ti = (NSInteger)interval;
    //    NSInteger seconds = ti % 60;
    //    NSInteger minutes = (ti / 60) % 60;
    //上面的计算方式不准确
    NSInteger seconds = ti % 60;
    NSInteger minutes = ti / 60;
    return [NSString stringWithFormat:@"%02ld:%02ld", (long)minutes, (long)seconds];
}

+(NSString *)getMMSSFromSS:(NSString *)totalTime
{
    
    NSInteger seconds = [totalTime integerValue];
    NSString *str_minute = [NSString stringWithFormat:@"%02ld",seconds/60];
    //format of second
    NSString *str_second = [NSString stringWithFormat:@"%02ld",seconds%60];
    //format of time
    NSString *format_time = [NSString stringWithFormat:@"%@:%@",str_minute,str_second];
    
    return format_time;
    
}


+(NSAttributedString *)getAttriNeedChangeString:(NSString *)string changeColor:(UIColor *)changeColor changeFont:(UIFont *)font sourceString:(NSString *)sourceString
{
    //    NSAttributedString *attributeStr;
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:sourceString];
    NSRange needStringRange = [sourceString rangeOfString:string options:NSCaseInsensitiveSearch];
    [str addAttribute:NSForegroundColorAttributeName value:changeColor range:needStringRange];
    [str addAttribute:NSFontAttributeName value:font range:needStringRange];
    return str;
}

+(NSString *)countNumAndChangeformat:(NSString *)num
{
    //获取前面的整数
    NSString *firstString;
    //小数点后面的小数
    NSString *lastString;
    
    //判断数字有没有小数点
    if ([num containsString:@"."]) {
        //截取小数点前后的数字字段
        NSArray *strArray = [num componentsSeparatedByString:@"."];
        firstString = strArray.firstObject;
        //对小数部分处理
        float lastFloat = [[NSString stringWithFormat:@"0.%@",strArray.lastObject] floatValue];
        //默认保留两位小数之后的字符串
        NSString *xiaoshuString = [NSString stringWithFormat:@"%.2f",lastFloat];
        //截取小数点之后的部分
        lastString = [xiaoshuString componentsSeparatedByString:@"."].lastObject;
    }else{
        firstString = num;
        lastString = @"";
    }
    
    int count = 0;
    long long int a = firstString.longLongValue;
    while (a != 0)
    {
        count++;
        a /= 10;
    }
    NSMutableString *string = [NSMutableString stringWithString:firstString];
    NSMutableString *newstring = [NSMutableString string];
    while (count > 3) {
        count -= 3;
        NSRange rang = NSMakeRange(string.length - 3, 3);
        NSString *str = [string substringWithRange:rang];
        [newstring insertString:str atIndex:0];
        [newstring insertString:@"," atIndex:0];
        [string deleteCharactersInRange:rang];
    }
    [newstring insertString:string atIndex:0];
    
    //拼接完整的字段
    if (lastString.length == 0) {
        return newstring;
    }else{
        NSString *allString = [NSString stringWithFormat:@"%@.%@",newstring , lastString];
        return allString;
    }
}

+(BOOL)isHasChineseWithStr:(NSString *)str
{
    for (int i=0; i<str.length; i++) {
        NSRange range =NSMakeRange(i, 1);
        NSString * strFromSubStr=[str substringWithRange:range];
        const char *cStringFromstr = [strFromSubStr UTF8String];
        if (strlen(cStringFromstr)==3) {
            //汉字
            return YES;
        } else if (strlen(cStringFromstr)==1) {
            //字母
        }
        
    }
    return NO;
}

+(BOOL)isAllNum:(NSString *)string
{
    unichar c;
    for (int i=0; i<string.length; i++) {
        c=[string characterAtIndex:i];
        if (!isdigit(c)) {
            return NO;
        }
    }
    return YES;
}

+(BOOL)isAllEnglish:(NSString *)string
{
    NSRegularExpression*tLetterRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[A-Za-z]"options:NSRegularExpressionCaseInsensitive error:nil];
    NSUInteger tLetterMatchCount = [tLetterRegularExpression numberOfMatchesInString:string options:NSMatchingReportProgress range:NSMakeRange(0, string.length)];
    
    if (tLetterMatchCount == string.length) {
        return YES;
    }else{
        return NO;
    }
    
}
+(BOOL)checkPassWord:(NSString *)passWord
{
    NSString * pattern  =   @"^[A-Za-z0-9_]{6,12}$";
    NSPredicate * pred  =   [NSPredicate predicateWithFormat:@"SELF MATCHES %@",pattern];
    return [pred evaluateWithObject:passWord];
}


+(BOOL)judgePassWordLegal:(NSString *)pass

{
    BOOL result = false;
    if ([pass length] >= 6){
        // 判断长度大于6位后再接着判断是否同时包含数字和字符
        NSString * regex = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$";
        NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
        result = [pred evaluateWithObject:pass];
    }
    return result;
}
+(BOOL)judgeInvitationCodeWith:(NSString *)codeString
{
    NSString *regex = @"^[A-Za-z0-9]{5,5}$";
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    
    if ([predicate evaluateWithObject:codeString] == YES) {
        return YES;
    }else{
        return NO;
    }
}
+(BOOL)isPhoneNumber:(NSString *)string
{
    //    NSString * MOBIL = @"^1(3[0-9]|4[579]|5[0-35-9]|7[01356]|8[0-9])\\d{8}$";
    //    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBIL];
    //    if ([regextestmobile evaluateWithObject:string]) {
    //        return YES;
    //    }
    //手机号只验证11位数字
    if (string.length == 11) {
        return YES;
    }
    return NO;
}
+(NSString *)phoneNumberasterisk:(NSString *)phoneNumberString
{
    
    if (phoneNumberString.length) {
        NSString *foreSubstr = [phoneNumberString substringWithRange:NSMakeRange(0, 3)];
        NSString *backSubstr = [phoneNumberString substringWithRange:NSMakeRange(phoneNumberString.length - 4, 4)];
        return [NSString stringWithFormat:@"%@****%@",foreSubstr,backSubstr];
    }else
    {
        return phoneNumberString;
    }
}
+(NSString *)phoneNumberFormate:(NSString *)phoneNumber
{
    
    int count = 0;
    long long int a = phoneNumber.longLongValue;
    while (a != 0)
    {
        count++;
        a /= 10;
    }
    NSMutableString *string = [NSMutableString stringWithString:phoneNumber];
    NSMutableString *newstring = [NSMutableString string];
    while (count > 4) {
        count -= 4;
        NSRange rang = NSMakeRange(string.length - 4, 4);
        NSString *str = [string substringWithRange:rang];
        [newstring insertString:str atIndex:0];
        [newstring insertString:@" " atIndex:0];
        [string deleteCharactersInRange:rang];
    }
    [newstring insertString:string atIndex:0];
    
    return newstring;
}
+(BOOL)checkUserIdCard:(NSString *)userIdCard
{
    //长度不为18的都排除掉
    if (userIdCard.length > 18) {
        return NO;
    }
    
    //校验格式
    NSString *regex2 = @"^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    BOOL flag = [identityCardPredicate evaluateWithObject:userIdCard];
    
    if (!flag) {
        return flag;    //格式错误
    }else {
        //格式正确在判断是否合法
        
        //将前17位加权因子保存在数组里
        NSArray * idCardWiArray = @[@"7", @"9", @"10", @"5", @"8", @"4", @"2", @"1", @"6", @"3", @"7", @"9", @"10", @"5", @"8", @"4", @"2"];
        
        //这是除以11后，可能产生的11位余数、验证码，也保存成数组
        NSArray * idCardYArray = @[@"1", @"0", @"10", @"9", @"8", @"7", @"6", @"5", @"4", @"3", @"2"];
        
        //用来保存前17位各自乖以加权因子后的总和
        NSInteger idCardWiSum = 0;
        for(int i = 0;i < 17;i++)
        {
            NSInteger subStrIndex = [[userIdCard substringWithRange:NSMakeRange(i, 1)] integerValue];
            NSInteger idCardWiIndex = [[idCardWiArray objectAtIndex:i] integerValue];
            
            idCardWiSum+= subStrIndex * idCardWiIndex;
            
        }
        //计算出校验码所在数组的位置
        NSInteger idCardMod=idCardWiSum%11;
        
        //得到最后一位身份证号码
        NSString * idCardLast= [userIdCard substringWithRange:NSMakeRange(17, 1)];
        //如果等于2，则说明校验码是10，身份证号码最后一位应该是X
        if(idCardMod==2)
        {
            if([idCardLast isEqualToString:@"X"]||[idCardLast isEqualToString:@"x"])
            {
                return YES;
            }else
            {
                return NO;
            }
        }else{//用计算出的验证码与最后一位身份证号码匹配，如果一致，说明通过，否则是无效的身份证号码
            if([idCardLast isEqualToString: [idCardYArray objectAtIndex:idCardMod]])
            {
                return YES;
            }
            else
            {
                return NO;
            }
        }
    }
    
}

+(BOOL)checkBankCard:(NSString *)bankCard
{
    if (bankCard.length < 16) {
        return NO;
    }
    NSInteger oddsum = 0;     //奇数求和
    NSInteger evensum = 0;    //偶数求和
    NSInteger allsum = 0;
    NSInteger cardNoLength = (NSInteger)[bankCard length];
    // 取了最后一位数
    NSInteger lastNum = [[bankCard substringFromIndex:cardNoLength-1] intValue];
    //测试的是除了最后一位数外的其他数字
    bankCard = [bankCard substringToIndex:cardNoLength - 1];
    for (NSInteger i = cardNoLength -1 ; i>=1;i--) {
        NSString *tmpString = [bankCard substringWithRange:NSMakeRange(i-1, 1)];
        NSInteger tmpVal = [tmpString integerValue];
        if (cardNoLength % 2 ==1 ) {//卡号位数为奇数
            if((i % 2) == 0){//偶数位置
                tmpVal *= 2;
                if(tmpVal>=10)
                    tmpVal -= 9;
                evensum += tmpVal;
            }else{//奇数位置
                oddsum += tmpVal;
            }
        }else{
            if((i % 2) == 1){
                tmpVal *= 2;
                if(tmpVal>=10)
                    tmpVal -= 9;
                evensum += tmpVal;
            }else{
                oddsum += tmpVal;
            }
        }
    }
    allsum = oddsum + evensum;
    allsum += lastNum;
    if((allsum % 10) == 0)
        return YES;
    else
        return NO;
}

+(NSString *)formatterBankCard:(NSString *)bankCard
{
    NSString *tempStr=bankCard;
    NSInteger size =(tempStr.length / 4);
    NSMutableArray *tmpStrArr = [[NSMutableArray alloc] init];
    for (int n = 0;n < size; n++){
        [tmpStrArr addObject:[tempStr substringWithRange:NSMakeRange(n*4, 4)]];
    }
    [tmpStrArr addObject:[tempStr substringWithRange:NSMakeRange(size*4, (tempStr.length % 4))]];
    tempStr = [tmpStrArr componentsJoinedByString:@" "];
    return tempStr;
}

+ (NSString *)adjustScreenImageName:(NSString *)name
{
    //传yidaoye_1返回yindaoye_1@2x
    
    if (isPhoneX) {
        return [NSString stringWithFormat:@"%@_x@3x",name];
    }
    switch ((int)[UIScreen mainScreen].scale) {
        case 1:
            return name;
            break;
        case 2:
            return [NSString stringWithFormat:@"%@@2x",name];
            break;
        case 3:
            return [NSString stringWithFormat:@"%@@3x",name];
            break;
        default:
            return name;
            break;
    }
    
    
}
+(BOOL)isMianCity:(NSString *)city
{
    if ([city isEqualToString:@"北京市"] || [city isEqualToString:@"上海市"] || [city isEqualToString:@"重庆市"] || [city isEqualToString:@"天津市"]) {
        return YES;
    }else
    {
        return NO;
    }
}


+ (NSString *)urlPramsStrWithDic:(NSDictionary *)params
{
    NSMutableArray *dparams = [[NSMutableArray alloc] initWithCapacity:params.count];
    for (NSString *key in params) {
        NSString *value= [params valueForKey:key];
        [dparams addObject:[NSString stringWithFormat:@"%@=%@",key,value]];
    }
    NSString *paramString = [dparams componentsJoinedByString:@"&"];
    return paramString;
}


+ (BOOL)isFloatNumString:(NSString *)str
{
    //大于0的非字母的数字
    NSString *newStr = [str stringByReplacingOccurrencesOfString:@"." withString:@""];
    if ([NSString isAllNum:newStr] && ![NSString isAllEnglish:newStr]) {
        return YES;
    }else
    {
        return NO;
    }
    
}
+ (BOOL)isMaxMoney:(NSString *)str
{
    //大于0的非字母的数字
    NSString *newStr = [str stringByReplacingOccurrencesOfString:@"." withString:@""];
    if ([NSString isAllNum:newStr] && ![NSString isAllEnglish:newStr] && [str floatValue] <= 4500) {
        return YES;
    }else
    {
        return NO;
    }
}

+(CGFloat)getHeightWithText:(NSString *)str font:(UIFont *)font MaxWidth:(CGFloat)MaxWidth lineSpace:(CGFloat)lineSpace
{
    if (!str||[str isKindOfClass:[NSNull class]]||[str isEqualToString:@""])
    {
        return 0.0;
    }
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentLeft;
    paraStyle.lineSpacing = lineSpace;
    paraStyle.hyphenationFactor = 0.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    
    NSDictionary *dic = @{NSFontAttributeName:font,
                          NSParagraphStyleAttributeName:paraStyle,
                          };
    
    CGSize size =  [str boundingRectWithSize:CGSizeMake(MaxWidth, MAXFLOAT)
                                     options:NSStringDrawingUsesLineFragmentOrigin  | NSStringDrawingUsesFontLeading
                                  attributes:dic
                                     context:nil].size;
    return size.height;
}



- (NSString *)pz_stringNumberByAdding:(NSString *)stringNumber
{
    return [self pz_stringNumberByAdding:stringNumber
                            withBehavior:[SYDecimalNumberHandler defaultStringNumberHandler]];
}
- (NSString *)pz_stringNumberBySubtracting:(NSString *)stringNumber
{
    return [self pz_stringNumberBySubtracting:stringNumber withBehavior:[SYDecimalNumberHandler defaultStringNumberHandler]];
}
- (NSString *)pz_stringNumberByMultiplyingBy:(NSString *)stringNumber
{
    return [self pz_stringNumberByMultiplyingBy:stringNumber withBehavior:[SYDecimalNumberHandler defaultStringNumberHandler]];
}
- (NSString *)pz_stringNumberByDividingBy:(NSString *)stringNumber
{
    return [self pz_stringNumberByDividingBy:stringNumber withBehavior:[SYDecimalNumberHandler defaultStringNumberHandler]];
}


- (NSString *)pz_stringNumberByAdding:(NSString *)stringNumber withBehavior:(SYDecimalNumberHandler *)handler
{
    return  [self pz_stringNumberByCalculationType:CalculationAdding by:stringNumber withBehavior:handler];
}
- (NSString *)pz_stringNumberBySubtracting:(NSString *)stringNumber withBehavior:(SYDecimalNumberHandler *)handler
{
    return  [self pz_stringNumberByCalculationType:CalculationSubtracting by:stringNumber withBehavior:handler];
}
- (NSString *)pz_stringNumberByMultiplyingBy:(NSString *)stringNumber withBehavior:(SYDecimalNumberHandler *)handler
{
    return  [self pz_stringNumberByCalculationType:CalculationMultiplying by:stringNumber withBehavior:handler];
}
- (NSString *)pz_stringNumberByDividingBy:(NSString *)stringNumber withBehavior:(SYDecimalNumberHandler *)handler
{
    return  [self pz_stringNumberByCalculationType:CalculationDividing by:stringNumber withBehavior:handler];
}


- (NSString *)pz_stringNumberByCalculationType:(CalculationType)type by:(NSString *)stringNumber withBehavior:(SYDecimalNumberHandler *)handler
{
    
    NSDecimalNumber *selfNumber = [NSDecimalNumber decimalNumberWithString:self];
    NSDecimalNumber *calcuationNumber = [NSDecimalNumber decimalNumberWithString:stringNumber];
    
    NSDecimalNumber *result = nil;
    if (CalculationAdding == type) {
        result = [selfNumber decimalNumberByAdding:calcuationNumber withBehavior:handler];
    }else if (CalculationSubtracting == type){
        result = [selfNumber decimalNumberBySubtracting:calcuationNumber withBehavior:handler];
    }else if (CalculationMultiplying == type){
        result = [selfNumber decimalNumberByMultiplyingBy:calcuationNumber withBehavior:handler];
    }else if (CalculationDividing == type){
        result = [selfNumber decimalNumberByDividingBy:calcuationNumber withBehavior:handler];
    }
    
    // 设置的精度
    short scale =  [handler scale];
    // 如果自定义了结果格式化工具使用自定义formatter
    NSNumberFormatter *numberFormatter = handler.numberFormatter?:PZDecimalNumberFormatter((NSUInteger)scale,handler.formatterStyle);
    return [numberFormatter stringFromNumber:result];
    
}

+(BOOL)judgeIntegerMultiple:(NSInteger)integer TextString:(NSString *)textString
{
    if (!textString.length) {
        return NO;
    }
    NSInteger textInteger = [textString integerValue];
    if (textInteger % integer == 0) {
        return YES;
    }else{
        return NO;
    }
    
}


@end
